public class code3 {
    //翻转二叉树：没到左右结点都为null就一直交换，不断递归
    public TreeNode invertTree(TreeNode root) {
        if(root == null) {
            return null;
        }
        //递归结束的标志
        if(root.left == null && root.right == null) {
            return root;
        }
        //交换左右值
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        //交换完根节点的左右结点，再继续向下交换
        invertTree(root.left);
        invertTree(root.right);

        return root;
    }
}
